﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Mahanet.Abyss.PathCalculation;

namespace motion
{
	public class CrossLayer : BaseLayer
	{
		protected class DrawData
		{
			public DrawData(Coordinate2D crossLocation, Color crossColor)
			{
				m_CrossColor = crossColor;
				m_CrossLocation = crossLocation;
			}

			public Coordinate2D m_CrossLocation { get; private set; }
			public Color m_CrossColor { get; private set; }
		}

		private List<DrawData> m_CrossesToDraw = new List<DrawData>();

		public CrossLayer(Control parentController)
            : base(parentController)
		{
		}

		public void AddCross(Coordinate2D location, Color color)
		{
			m_CrossesToDraw.Add(new DrawData(location, color));
		}

		public void ClearCrosses()
		{
			m_CrossesToDraw.Clear();
		}

		protected override void OnLayerPaint(PaintEventArgs pe)
		{
			foreach (DrawData cross in m_CrossesToDraw)
			{
        using (Pen pen = new Pen(cross.m_CrossColor, 1.7f))
        {
          int crossSize = 5;
          int crossMidGapSize = 2;

          pe.Graphics.DrawLine(pen,
                     new Point((int)cross.m_CrossLocation.X - crossSize, (int)cross.m_CrossLocation.Y),
                     new Point((int)cross.m_CrossLocation.X - crossMidGapSize + 1, (int)cross.m_CrossLocation.Y));
          pe.Graphics.DrawLine(pen,
                     new Point((int)cross.m_CrossLocation.X + crossMidGapSize, (int)cross.m_CrossLocation.Y),
                     new Point((int)cross.m_CrossLocation.X + crossSize + 1, (int)cross.m_CrossLocation.Y));
          pe.Graphics.DrawLine(pen,
                     new Point((int)cross.m_CrossLocation.X, (int)cross.m_CrossLocation.Y - crossSize),
                     new Point((int)cross.m_CrossLocation.X, (int)cross.m_CrossLocation.Y - crossMidGapSize + 1));
          pe.Graphics.DrawLine(pen,
                     new Point((int)cross.m_CrossLocation.X, (int)cross.m_CrossLocation.Y + crossMidGapSize),
                     new Point((int)cross.m_CrossLocation.X, (int)cross.m_CrossLocation.Y + crossSize + 1));
        }
			}
		}
	}
}
